package com.fang.algorithm.zuo.string;

import java.util.ArrayList;
import java.util.List;

/**
 * 打印一个字符串的全部子序列
 */
public class Test01_PrintStrChildStr {
    public static void main(String[] args) {
        String str = "abcd";
        List<String> ans = printStrChildStr(str);
        System.out.println(ans.toString());
    }

    private static List<String> printStrChildStr(String str) {
        List<String> ans = new ArrayList<>();
        if (null == str || "".equals(str)) {
            return ans;
        }
        char[] chars = str.toCharArray();
        createChildStr(chars, 0, ans, "");
        return ans;
    }

    private static void createChildStr(char[] chars, int index, List<String> ans, String child) {
        if (chars.length == index) {
            ans.add(child);
            return;
        }
        String no = child;
        createChildStr(chars, index + 1, ans, no);
        String yes = child + chars[index];
        createChildStr(chars, index + 1, ans, yes);
    }
}
